package ch.usi.inf.pf2.editor;

import javax.swing.border.Border;

import ch.usi.inf.pf2.Sheet;
import ch.usi.inf.pf2.cell.Cell;

/**
 * Used to change the cell border
 * 
 * @author Lorenzo Baracchi
 *
 */
public class ChangeCellBorder extends CellManagement
{
    private Border oldBorder;
    private Border newBorder;

    
    /**
     * Create an object able to change the border of the cell.
     * @param sheet The sheet where the cell is.
     * @param rowIndex The numeric index of the cell.
     * @param columnIndex The literal index of the cell.
     * @param newBorder The new border type wanted for the cell.
     */
    public ChangeCellBorder (Sheet sheet, int rowIndex, int columnIndex, Border newBorder)
    {
	   super(sheet, rowIndex, columnIndex);
	   this.newBorder=newBorder;
    }

    
    /**
     * Change the border type of the cell and store the old one
     * into oldBorder for possible undo actions.
     */
    @Override
    public void evaluate ()
    {
	   Cell c = sheet.getCell(getColumnIndex(), getRowIndex());
	   oldBorder=c.getBorderType();
	   c.setBorderType(newBorder);
    }

    
    /**
     * Allow to set in the field oldBorder
     * a wanted old border type for the cell.
     * @param oldBorder The old border type of the cell.
     */
    public void setOldBorder (Border oldBorder)
    {
	   this.oldBorder = oldBorder;
    }

    
    /**
     * @return The old border type of the cell.
     */
    public Border getOldBorder ()
    {
	   return oldBorder;
    }

    
    /**
     * Allow to set in the field newBorder
     * the new border type of the cell.
     * @param newBorder The new border type of the cell.
     */
    public void setNewBorder (Border newBorder)
    {
	   this.newBorder = newBorder;
    }

    
    /**
     * @return The new border type of the cell.
     */
    public Border getNewBorder ()
    {
	   return newBorder;
    }

    
    /**
     * Undo the previous change of border type.
     */
    @Override
    public void restore ()
    {
	   Cell c = sheet.getCell(getColumnIndex(), getRowIndex());
	   c.setBorderType(getOldBorder());
    }


}
